<!DOCTYPE html>
<!--suppress HtmlUnknownAttribute -->
<html lang="zh-Hans-CN" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header"/>
  <title>修改水文代码</title>
</head>
<body>
<form class="layui-form" th:object="${code}">
  <div class="mainBox">
    <div class="main-container">
      <input name="id" th:field="*{id}" type="hidden">
      <div class="layui-form-item">
        <label for="code" class="layui-form-label">代码：</label>
        <div class="layui-input-block">
          <input id="code" class="layui-input" lay-verify="required" name="code"
                 placeholder="请输入代码" th:field="*{code}" type="text"/>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="name" class="layui-form-label">名称：</label>
        <div class="layui-input-block">
          <input id="name" class="layui-input" lay-verify="required" name="name"
                 placeholder="请输入名称" th:field="*{name}" type="text"/>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="remark" class="layui-form-label">注释：</label>
        <div class="layui-input-block">
          <textarea id="remark" class="layui-textarea" lay-verify="required" name="remark"
                    placeholder="请输入注释" th:field="*{remark}" type="text"></textarea>
        </div>
      </div>
    </div>
  </div>
  <div class="bottom">
    <div class="button-container">
      <button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="well-code-update" lay-submit=""
              type="submit">
        <i class="layui-icon layui-icon-ok"></i>
        提交
      </button>
      <button class="pear-btn pear-btn-sm" type="reset">
        <i class="layui-icon layui-icon-refresh"></i>
        重置
      </button>
    </div>
  </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.jquery;

    let prefix = "/well/code/";

    form.on('submit(well-code-update)', function (data) {
      $.ajax({
        url: prefix + 'update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'put',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name));
              parent.layui.table.reload("well-code-table");
            });
          } else {
            layer.msg(result.msg, {icon: 2, time: 1000});
          }
        }
      })
      return false;
    });
  });
</script>
</html>
